package socket;

import com.sun.media.sound.SoftReverb;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Sever {
    private ServerSocket serverSocket;
    public Sever()  {
        try {
            System.out.println("正在启动服务器");
            serverSocket =new ServerSocket(8488);
            System.out.println("服务器启动完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    public  void start() {
        System.out.println("等待客户端连接");

        try {

        while(true) {
            Socket socket = serverSocket.accept();
            InputStream sis = socket.getInputStream();
            InputStreamReader sos = new InputStreamReader(sis, StandardCharsets.UTF_8);
            BufferedReader ses = new BufferedReader(sos);
            String message;
            while ((message = ses.readLine()) != null) {
                System.out.println("客户端说：" + message);
            }

        }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("客户端连接成功");

    }

    public static void main(String[] args) {
        Sever sever=new Sever();
        sever.start();
    }
}
